using System;
using FluentNHibernate.Cfg.Db;
using Orchard.Environment.Extensions;

namespace Orchard.Contrib.Modules.NHibSecondLevelCache.Data.Providers
{
    [OrchardSuppressDependency("Orchard.Data.Providers.SqlServerDataServicesProvider")]
    [Serializable]
    public class SqlServerDataServicesProvider : AbstractDataServicesProvider {
        private readonly string _dataFolder;
        private readonly string _connectionString;
        private Orchard.Data.Providers.SqlServerDataServicesProvider _base;

        public SqlServerDataServicesProvider(string dataFolder, string connectionString) {
            _dataFolder = dataFolder;
            _connectionString = connectionString;
            _base = new Orchard.Data.Providers.SqlServerDataServicesProvider(dataFolder, connectionString);
        }

        public static string ProviderName {
            get { return Orchard.Data.Providers.SqlServerDataServicesProvider.ProviderName; }
        }

        public override IPersistenceConfigurer GetPersistenceConfigurer(bool createDatabase) {

            var persistence = _base.GetPersistenceConfigurer(createDatabase) as MsSqlConfiguration;
            return persistence.Cache(cache => cache.ProviderClass<NHibernate.Caches.SysCache.SysCacheProvider>());
        }
    }
}